package info.androidhive.sqlite;

import info.androidhive.sqlite.model.Todo;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class TodoListAdapter extends ArrayAdapter<Todo> {
	private ArrayList<Todo> arr;

	public TodoListAdapter(Context context, int textViewResourceId,
			ArrayList<Todo> arr) {
		super(context, textViewResourceId, arr);
		this.arr = arr;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.row, null);
		}
		Todo todo = arr.get(position);
		if (todo != null) {
			TextView tt = (TextView) v.findViewById(R.id.toptext);
			//TextView bt = (TextView) v.findViewById(R.id.bottomtext);
			if (tt != null) {
				tt.setText(todo.getNote());
			}
			/*if (bt != null) {
				bt.setText("pkey : " + todo.getId());
			}*/
		}
		return v;
	}
}
